package com.qinsoft.frame.taobao.task;

import java.util.TimerTask;

import com.qinsoft.business.user.dao.UserDao;
import com.qinsoft.frame.constants.QinCodeConstants;
import com.qinsoft.frame.taobao.onsale.OnSaleTask;

public class TopTask extends TimerTask
{
    private ThreadPool pool;
    private OnSaleTask saleTask = new OnSaleTask();
    private LogTask logTask = new LogTask();
    private UserTask userTask = new UserTask();
    
    public TopTask()
    {
        super();
    }

    public TopTask(ThreadPool pool)
    {
        super();
        this.pool = pool;
    }

    @Override
    public void run()
    {
        pool.processTask(saleTask);
        pool.processTask(logTask);
        pool.processTask(userTask);
    }
    
    public void stop()
    {
        saleTask.stop();
    }
}

class LogTask implements Runnable
{
    @Override
    public void run()
    {
        while (true)
        {
            try
            {
//                OnSaleLogDao.delete();
//                RecomLogDao.delete();
                Thread.sleep(QinCodeConstants.SYSTEM_FIXED_TIME);
            }
            catch (Exception e)
            {
                TaskException.getResultMessage(e);
            }
        }
    }
}

class UserTask implements Runnable
{
    @Override
    public void run()
    {
        while (true)
        {
            try
            {
                UserDao.delete();
                Thread.sleep(QinCodeConstants.SYSTEM_FIXED_TIME);
            }
            catch (Exception e)
            {
                TaskException.getResultMessage(e);
            }
        }
    }
}
